package com.disapand.dingdang.extension

import com.disapand.dingdang.vo.PageVO
import org.ktorm.entity.EntitySequence
import org.ktorm.entity.drop
import org.ktorm.entity.take
import org.ktorm.entity.toList
import org.ktorm.schema.BaseTable

/**
 * @author disapand
 * @date 2022/2/27 - 10:41 星期日
 */

/**
 * ktorm 分页扩展函数
 *
 * @param E
 * @param T
 * @param current
 * @param pageSize
 * @return
 */
fun <E : Any, T : BaseTable<E>> EntitySequence<E, T>.page(current: Int = 1, pageSize: Int = 20): PageVO<E> {
    val total = this.totalRecords
    val list = this.drop((current - 1) * pageSize).take(pageSize).toList()
    return PageVO(
        total,
        current,
        pageSize,
        list
    )
}